

function deg2rad(a) {
	return a * Math.PI / 180;
}

function rad2deg(a) {
	return a * 180 / Math.PI;
}

function frac(a) {
	return (a - Math.floor(a));
}

//Distance(47.731016,9.253851 , 47.731016, 8.253851 );
exports.Distance = function(b1, l1, b2, l2) {

	r0 = 6371.0;
	a = deg2rad(90 - b1);
	b = deg2rad(90 - b2);
	gamma = deg2rad(Math.abs(l2 - l1));
	c = Math.acos(Math.cos(a) * Math.cos(b) + Math.sin(a) * Math.sin(b) * Math.cos(gamma));
	s = (a + b + c) / 2;
	if (l1 == l2) {
		if (b1 < b2) {
			alpha = Math.PI;
			beta = 0;
		} else {
			alpha = Math.PI;
			beta = Math.PI;
		}
	} else {
		alpha = Math.acos((Math.cos(a) - Math.cos(b) * Math.cos(c)) / (Math.sin(c) * Math.sin(b)));
		beta = Math.acos((Math.cos(b) - Math.cos(c) * Math.cos(a)) / (Math.sin(c) * Math.sin(a)));
	}
	e = alpha + beta + gamma - Math.PI;
	A = r0 * r0 * e;
	ss = (alpha + beta + gamma) / 2;
	ka = a * r0;
	kb = b * r0;
	kc = c * r0;
	if (beta != 0) {
		bearing = 360 - rad2deg(beta);
	} else {
		bearing = 0;
	}
	revbearing = rad2deg(alpha);
	if (((l2 - l1) > 0) || ((l2 == l1) && (b2 < b1))) {
		bearing = 360 - bearing;
		revbearing = 360 - revbearing;
	}

	kc = Math.round(1000 * kc);

	bearing = Math.round(100 * bearing) / 100;

	revbearing = Math.round(100 * revbearing) / 100;

	return kc;

}
//Berechne(47.731016,9.253851 , 47.731016, 8.253851 );

